from flask import Flask
import config
import json
import datetime
from flask import make_response
from flask import request
from flask import redirect
from flask import abort
app = Flask(__name__)
'''
@app.route('/json')
def hello_world():
    #print("wulalala")
    hello = {"name":"stranger", "say":"hello"}
    return json.dumps(hello)

@app.route('/article/<id>')
def article(id):
    return '您请求的参数：' +str(id),500
@app.route('/status_500')
def status_500():
    return "hello",500

@app.route('/set_header')
def set_header():
    resp=make_response('<h1>这是定制HTTP报头的练习<h>')
    resp.headers['X-Something']='A value'
    resp.headers['Server']='hello,lys'
    return resp

@app.route('/set_cookie')
def set_cookie():
    response=make_response("<h2>设置cookie</h2>")
    outdate=datetime.datetime.now()+datetime.timedelta(days=30)
    response.set_cookie('username','evancess',expires=outdate)
    return response
@app.route('/get_cookie')
def get_cookie():
    name=request.cookies.get('username')
    return name

@app.route('/del_cookie')
def del_cookie():
    response=make_response('delete cookie(删除cookie)')
    response.set_cookie('uesrname','',expires=0)
    return response

@app.route('/del_cookie2')
def del_cookie():
    response=make_response('第二中方法删除cookie')
    response.delete_cookie('username')
    return response

@app.route('/redir')#重定向到其他网站
def redir():
    return redirect('https://www.baidu.com')
'''
@app.route('/user/<id>')
def get_user(id):
    if int(id)<10:
        abort(404)
    return "<h1>抛出404，嘿嘿嘿</h1>"+str(id)


if __name__ == '__main__':
    app.run(debug=True)

















